interface SheetItem{
    question_id:string,
    checked:boolean,
    last_check_right:boolean,
    accuracy:number,
    order:number,
    qtype:string,
}

interface GetSheetFunc{
    (key:number):Promise<SheetItem[]>
}

async function fectch_answer_sheet(api:string){
    const res=await fetch(api)
    let sheet= (await res.json()) as SheetItem[]
    // sheet.forEach(s=>random_sheet(s))
    return sheet
}

async function get_year_answer_sheet(year:number){
    const api='http://127.0.0.1:8000/answersheet/year/'+year
    return await fectch_answer_sheet(api)
}

async function get_chapter_answer_sheet(chapter_id:number){
    const api='http://127.0.0.1:8000/answersheet/chapter/'+chapter_id
    return await fectch_answer_sheet(api)    
}

function random_sheet(sheet:SheetItem){
    sheet.last_check_right=Math.random()>0.5
    sheet.checked=Math.random()>0.5
    sheet.accuracy=Math.random()
}

export {SheetItem,GetSheetFunc,get_year_answer_sheet,get_chapter_answer_sheet}